<!-- 入驻列表 -->
<style>
    th {
        text-align: center;
    }
    .table>tbody>tr>td {
        line-height: 60px;
        text-align: center;
        height: 50px;
        margin: 0px;
        font-weight:normal;
    }
    #data_page .table>tbody>tr>td:last-child{
        text-align: center;
    }
	font{ margin: 0px auto;}
	#myModal .modal-dialog {
		width: 80%;
	}
    #orderinfo td{font-weight: normal !important}
</style>
<!-- css -->
<link href="__PUBLIC__/ganged/Css/bootstrap.css" rel="stylesheet" type="text/css" />

<div id="data_page" class="in_page">
    <div class="panel panel-default">
        <div class="panel-body">
            <form class="form-inline" method="get" name="keyword" id="keyword">
                <button type="button" class="btn btn-sm btn-default bs_type" status="0">全部订单</button>
                <button type="button" class="btn btn-sm btn-primary bs_type" status="1">待付款订单</button>
                <button type="button" class="btn btn-sm btn-primary bs_type" status="2">待发货订单</button>
                <button type="button" class="btn btn-sm btn-primary bs_type" status="3">待收货订单</button>
                <button type="button" class="btn btn-sm btn-primary bs_type" status="4">已完成订单</button>
                <button type="button" class="btn btn-sm btn-primary bs_type" status="5">已关闭订单</button>
                <div class="form-group">
                    <input type="text" class="form-control" value="{$order_sn}" id="exampleInputName2" name="order_sn" placeholder="订单编号">
                </div>
                <button type="submit" class="btn btn-sm btn-default">搜索</button>
            </form>
        </div>
    </div>
    <table class="table table-striped table-bordered table-condensed">
        <thead>
            <tr>
                <th>订单号</th>
                <th>用户信息</th>
                <th>订单详情</th>
                <th>订单状态</th>
                <th>手输金额</th>
                <th>订单金额</th>
                <th>反馈</th>
                <th>下单时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <volist name="list" id="li">
                <tr>
                    <td>{$li.order_sn}</td>
                    <td>昵称：{$li.user_name}<br/>手机号：{$li.phone}</td>
                    <td width="250px">
                        <button type="button" class="btn btn-sm btn-success order_info" data-order_sn="{$li.order_sn}" data-toggle="modal" data-target="#myModal">订单详情</button>
                    </td>
                    <td>{$li.orser_status}</td>
                    <td>{$li.pay_money}</td>
                    <td>{$li.order_money}</td>
                    <td>
                        <if condition="$li['is_feedback'] eq 1">
                            <button type="button" class="btn btn-sm btn-success feedback_btn" data-content="{$li.feedback_content}" data-toggle="modal" data-target="#feedback">反馈内容</button>
                        <else />
                            <font color="black">暂无反馈</font>
                        </if>
                    </td>
                    <td>{:date('Y-m-d H:i:s',$li['create_time'])}</td>
                    <td>
                        <if condition="isset($li['order_btn']['dqr_btn'])  && $li['order_btn']['dqr_btn'] == 1">
                            <button type="button" class="btn btn-sm btn-success dqr_btn" data-toggle="modal" data-target="#dqr_btn" data-id="{$li.id}">待确认</button>
                        </if>
                        <if condition="isset($li['order_btn']['yqr_btn'])  && $li['order_btn']['yqr_btn'] == 1">
                            <button type="button" class="btn btn-sm btn-default">已确认</button>
                        </if>
                        <if condition="isset($li['order_btn']['jy_colse'])  && $li['order_btn']['jy_colse'] == 1">
                            <font color="black">已关闭交易</font>
                        </if>
                        <if condition="isset($li['order_btn']['jy_cancel'])  && $li['order_btn']['jy_cancel'] == 1">
                            <font color="black">已取消交易</font>
                        </if>
                        <if condition="isset($li['order_btn']['colse_order'])  && $li['order_btn']['colse_order'] == 1">
                            <button type="button" class="btn btn-sm btn-danger Cancel" data-id="{$li.id}" p_type="del">取消订单</button>
                        </if>
                        <if condition="isset($li['order_btn']['to_shipping'])  && $li['order_btn']['to_shipping'] == 1">
                            <button type="button" class="btn btn-sm btn-success delivery" data-toggle="modal" data-target="#delivery" data-id="{$li.id}">发货</button>
                        </if>
                        <if condition="isset($li['order_btn']['wait_sh'])  && $li['order_btn']['wait_sh'] == 1">
                            <font color="black">待收货</font>
                        </if>
                        <if condition="isset($li['order_btn']['complete'])  && $li['order_btn']['complete'] == 1">
                            <font color="black">已完成</font>
                        </if>
                    </td>
                </tr>
            </volist>
        </tbody>
    </table>
</div>
<div>{$page}</div>

<!-- 发货 -->
<div class="modal fade" id="dqr_btn" tabindex="-1" role="dialog" aria-labelledby="myModalLabela" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabela">确认订单</h4>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default btn-primary dqr_btn_submit" data-dismiss="modal">确认</button>
            </div>
        </div>
    </div>
</div>


<!-- 订单详情 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    订单号：
                </h4>
            </div>
            <div class="modal-body">
                <table class="table table-striped table-bordered table-condensed">
                    <thead>
                        <tr>
                            <th>商品名称</th>
                            <th>属性</th>
                            <th>单价</th>
                            <th>数量</th>
                            <th>合计</th>
                        </tr>
                    </thead>
                    <tbody id="orderinfo">

                    </tbody>
                </table>
                <p class="infoname"></p>
                <p class="infophone"></p>
                <p class="muted"></p>
                <p class="infoprice"></p>
                <p class="logistics_code"></p>
                <p class="logistics_type"></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 发货 -->
<div class="modal fade" id="delivery" tabindex="-1" role="dialog" aria-labelledby="myModalLabela" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabela">发货</h4>
            </div>
            <div class="modal-body">
                <form id="bjy-form" action="{:U('delivery')}" class="form-horizontal">
                    <input type="hidden" class="form-control" id="order_id" name="order_id"/>
                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label" >物流/快递单号:</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="shipping_code" name="shipping_code"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">物流/快递类型:</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="shipping_name" name="shipping_name"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="button" class="btn btn-primary" id="delivery_button">提交</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 反馈 -->
<div class="modal fade" id="feedback" tabindex="-1" role="dialog" aria-labelledby="myModalLabela" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabela">反馈内容</h4>
            </div>
            <div class="modal-body" id="feedback_content">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<style>
    #img{
      width:700px;
      height:550px;
      position: absolute;
      top:5%;
      left:20%;
      background-color: #FFFFFF;
      border-radius: 10px;
      box-shadow:10px 10px 10px 5px #888888;
    }
    
    #order{
        width:100px;
        height:20px;
        display: block;
    }
    
    #Stick{
      width:500px;
      height:300px;
      position: absolute;
      top:5%;
      left:20%;
      background-color: #FFFFFF;
      border-radius: 10px;
      box-shadow:10px 10px 10px 5px #888888;    
    }
    
    #tuichu{
        position: absolute;
        right:0px;
        bottom:0px;
    }
</style>
<script>
    $(function(){
        //删除店铺
        $(".del").click(function(obj){
            $_this = $(this);
            var id = $(this).attr("d_id");
            if(confirm("您确认删除吗?")){
                $.post("{:U('del')}", {'id':id},function(obj){
                    alert(obj.m);
                    if(obj.s){
                        $_this.parent().parent().remove();
                        // if(typeof(obj.url) != undefined && obj.url){
                        //     location.href = obj.url;
                        // }
                    }
                })
            }
            return false;
        }) 
        $(".ajax-post").click(function(t){
            var $this = $(t);
            var url = $this.attr('href');
            if($this.hasClass('confirm')){
                if(confirm($this.data('original-title'))){

                }
            }else{
                $.post(url, {},function(obj){
                    if(obj.status){
                        if(typeof(obj.url) != 'undefined' && obj.url){
                            location.href = obj.url;
                        }
                    }else{
                        alert(obj.info);
                    }
                })
            }
            return false;
        })    


        $('.bs_type').click(function() {
            var type = $(this).attr('status');
            if(type) {
                location.href = "{:U('')}?status=" + type;
            } else {
                location.href = "{:U('')}";
            }
        });

        // 订单详情
        $(".order_info").on('click', function(){
            var order_sn = $(this).data('order_sn');
            $("#myModalLabel").text("订单号：" + order_sn);
            var url = "{:U('order_goods')}";
            $.post(url, {
                order_sn: order_sn
            }, function(obj) {
                if(obj.status) {
                    var order_goods = obj.order_goods;
                    var order = obj.order;
                    var html = "";
                    $('#orderinfo').empty();
                    $.each(order_goods, function(i, d) {
                        html += `<tr>
                                    <th>`+d.goods_name+`</th>
                                    <th>`+d.attr_name+`</th>
                                    <th>`+d.price+`</th>
                                    <th>`+d.buy_num+`</th>
                                    <th>`+d.price*d.buy_num+`</th>;
                                </tr>`;
                    })
                    $('#orderinfo').append(html);
                    $('.muted').text("收货人地址：" + order.pro+' '+order.city+' '+order.area+' '+order.address);
                    $('.infoprice').text("总价：￥" + order.pay_money);
                    $('.infophone').text("收货人联系方式：" + order.phone);
                    $('.infoname').text("收货人：" + order.user_name);
                    $('.logistics_code').text("物流/快递单号：" + order.shipping_code);
                    $('.logistics_type').text("物流/快递类型：" + order.shipping_name);
                }
            })
        });

        $('.delivery,.dqr_btn').click(function() {
            $("#order_id").val($(this).data('id'))
        })
        
        $('.feedback_btn').click(function() {
            $("#feedback_content").html($(this).data('content'))
        })

        // 发货单提交
        $("#delivery_button").on('click', function(){
            var $form = $("#bjy-form");
            var data = $form.serialize(); 
            $.post($form.attr('action'), data, function(res, textStatus, xhr) {
                if(res.status){
                    location.href = "{:U('index')}";
                }
            });
        });

        $(".dqr_btn_submit").on('click', function(){
            $.post("{:U('qr_order')}", {'order_id':$("#order_id").val()}, function(res, textStatus, xhr) {
                if(res.status){
                    location.reload();
                }
            });
        });
    })
</script>
